package com.rosh.rpc.core.netty.handler;

import com.rosh.rpc.core.data.RpcResponse;
import com.rosh.rpc.core.netty.request.RpcRequestHolder;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.DefaultPromise;

/**
 * @Description:
 * @Author: rosh
 * @Date: 2022/6/14 22:41
 */
@ChannelHandler.Sharable
public class RpcResponseHandler extends SimpleChannelInboundHandler<RpcResponse> {


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, RpcResponse msg) throws Exception {
        DefaultPromise<RpcResponse> requestPromise = RpcRequestHolder.getRequestPromise(msg.getRequestId());
        if (requestPromise != null) {
            requestPromise.setSuccess(msg);
        }
    }
}
